package cn.masterj.springcloud.controller;

import cn.masterj.springcloud.CommonResult;
import cn.masterj.springcloud.entity.Payment;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

/**
 * @author masterJ
 * @create 2020-04-03 10:23
 */
@RestController
@RequestMapping("/consumer")
@Slf4j
public class OrderController {
    @Autowired
    private RestTemplate restTemplate;

    public static final String PAYMENT_URL = "http://CLOUD-PROVIDER-PAYMENT";

    @GetMapping("/getById/{id}")
    public CommonResult getById(@PathVariable("id") Long id){
        CommonResult commonResult = restTemplate.getForObject(PAYMENT_URL + "/payment/getById/" + id, CommonResult.class);
        log.info("**************getById**************" + commonResult);
        return commonResult;
    }

    @PostMapping("/create")
    public CommonResult create(@RequestBody Payment payment){
        CommonResult commonResult = restTemplate.postForObject(PAYMENT_URL + "/payment/create", payment, CommonResult.class);
        log.info("**************create**************" + commonResult);
        return commonResult;
    }
}
